home *** CD-ROM | disk | FTP | other *** search
- Path: news.cuny.edu!not-for-mail
- From: dzielins@its.brooklyn.cuny.edu (Daniel Zielinski)
- Newsgroups: comp.lang.c
- Subject: Re: help with queue
- Date: 19 Apr 1996 20:50:20 -0400
- Organization: Brooklyn College
- Message-ID: <4l9ccc$k0l@itsop2.its.brooklyn.cuny.edu>
- References: <4l73q1$148@itsop2.its.brooklyn.cuny.edu> <4l89sc$kf6@sparcserver.lrz-muenchen.de>
- NNTP-Posting-Host: itsop2.its.brooklyn.cuny.edu
-
- >>this is QUEUE.c
- >
- >>#include "QUEUE.h"
- >>#include <assert.h>
- >>#include <stdio.h>
- >
- >[insertQueue edited]
- >
- >>int
- >>emptyQueue(Queue q) {
- >> assert((q.front==NULL && q.rear==NULL) || (q.front!=NULL &&
- >> q.rear!=NULL));
- >> return q.front==NULL;
- >>}
- >
- >This function obviously checks whether a queue is empty or not. It
- >returns 1 if the queue is empty, 0 if it is not empty.
- >
- >>DataType
- >>removeQueue(Queue *qp) {
- >> Node *np;
- >> DataType d;
- >
- >> assert(!emptyQueue(*qp)); <-------- THIS IS THE LINE
- >
- >The implementor of your queues states that his removeQueue() function
- >is not able to remove something from an empty queue. Since (s)he
- >wants to return the value of the removed node, this is a sane
- >assumption.
- >
- >> np=qp->front;
- >> d=np->data;
- >> qp->front=np->next;
- >> if (qp->front==NULL)
- >> qp->rear=NULL;
- >> deleteNode(np);
- >> return d;
- >>}
- >
- >>void
- >>initQueue(Queue *qp) {
- >> qp->front=qp->rear=NULL;
- >>}
- >
- >This creates an empty queue. Your implementation of a queue assumes
- >that only queues that are not empty can be passed to removeQueue().
- >
- >Kurt
- >--
- >| Kurt Watzka Phone : +49-89-2180-6254
- >| watzka@stat.uni-muenchen.de
-
- Yes I know all of this. I know what each function does. The question is...
-
- assertion in removeQueue fails, even though the QUEUE is not empty. (at least
- to my knowlege)
-
- my test driver contains the following:
-
-
- #include <stdio.h>
- #include "node.h"
- #include "QUEUE.h"
-
- main() {
- Queue q1,q2;
- int i=0;
-
- initQueue(&q1);
- while (i<100) {
- insertQueue(&q1,i);
- i++;
- }
- i=0;
- while(i<100) {
- printf("%d\n",removeQueue(&q1));
- i++;
- }
- }
-
- the program should print 1\n2\n3\n.... instead it prints assertion failed in QUEUE.c line 31 (removeQUEUE).
-
- The Question is why does it happen? the QUEUE is not empty.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-